
(function() {
	dojo.provide("ws.main");
	dojo.require("dijit.layout.BorderContainer");
	dojo.require("dijit.layout.ContentPane");
	dojo.require("dijit.dijit");
	dojo.require("dijit.Tree");
	dojo.require("dijit.tree.ForestStoreModel");
	dojo.require("dijit.tree.TreeStoreModel");
	dojo.require("dojo.data.ItemFileReadStore");
	dojo.require("dijit.layout.LayoutContainer");

	var main = ws.main;
	function __loadPage(href) {
		dojo.byId("iframe_content").src = href;
	}
	main.startup = function() {
		main.navStore = new dojo.data.ItemFileReadStore({
			url : contextpath + '/welcome/menu.do'
		});
		main.navModel = new dijit.tree.ForestStoreModel({
			store : main.navStore,
			rootId : "id",
			rootLabel : "boast菜单"
		});
		main.navTree = new dijit.Tree({
			id : "navigator",
			region : "left",
			style : "width:200px;overflow:auto",
			splitter : true,
			openOnDblClick : true,
			onClick : function(item, node, event) {
				if (typeof item.programid != "undefined" && item.programid != 0 && item.programid != -1) {
					// TODO 打开表单
					__loadPage(contextpath + "/" + item.programid + ".prog?r=" + Math.random());
				}
				return true;
			},
			model : main.navModel
		});
		
		
		main.workspace = new dijit.layout.ContentPane({
			id : "workspace",
			region : "center"
		});

		var appContainer = main.appContainer = new dijit.layout.BorderContainer({
			style : "width:100%;height:100%"
		});

		
		dojo._destroyElement(dojo.byId("bafLoading"));
		dojo.place(appContainer.domNode, dojo.body(), "first");
		main.ContentPane =  new dijit.layout.ContentPane({
			id : "_title",
			region : "top",
			style : "height:40px;padding:0;background:#0d4b89;vertical-align:middle;border-bottom:1px solid #B6B6F5"
		});
		var title = dojo.byId("port_title");
		main.ContentPane.setContent(dojo.byId("port_title").innerHTML);
		main.workspace.setContent(dojo.byId("port_content").innerHTML);
		dojo._destroyElement(title);
		dojo._destroyElement(dojo.byId("port_content"));
		
		appContainer.addChild(main.ContentPane);
		appContainer.addChild(main.navTree);
		appContainer.addChild(main.workspace);
		appContainer.startup();

		window.onresize = function() {
			appContainer.layout();
		}
	}
})();